﻿using System.Windows.Forms;
using System.Drawing;
namespace RPG1
{
    class Warrior : Role
    {
        public Warrior(string name, int originalLife, int currentLife, int damage, int agile, int brains, int speed,
            PictureBox picBox, Label bottomLabel, Label topLabel, Weapon wpn)
            : base(name, originalLife, currentLife, damage, agile, brains, speed, picBox, bottomLabel, topLabel, wpn)
        {
            // 继承自父类的属性
            Name = name;
            OriginalLife = originalLife;
            CurrentLife = currentLife;
            Damage = damage;
            Agile = agile;
            Brains = brains;
            Speed = speed;
            PicBox = picBox;
            BottomLabel = bottomLabel;
            TopLabel = topLabel;
            Wpn = wpn;
        }
        public override int getAttack()
        {
            return (int)(Damage * 4.5 + Brains * 2 + Wpn.Atk);
        } //勇士攻击力 = 力量 * 4.5 + 智力 * 1.2 + 武器的攻击力
        public override int getDefense()
        {
            return (int)(Agile * 8 + Damage * 2.5 + Brains + Wpn.Defense);
        } //勇士防御力 = 敏捷 * 8 + 力量 * 2.5 + 智力 * 1 + 武器的防御力
        public void goBack()
        {
            //返回，当前位置=原始位置
            int diffX = OriginaLocation.X - PicBox.Location.X;
            int diffY = OriginaLocation.Y - PicBox.Location.Y;
            for (int i = 1; i <= 10; i++)
            {
                PicBox.Location = new Point(PicBox.Location.X + diffX / 10,
                    PicBox.Location.Y + diffY / 10);
                TopLabel.Location = PicBox.Location;
                BottomLabel.Location = PicBox.Location;
                Delay(20000);
            }
        }
        public override void attack(Role role)
        {
            // 移动到怪兽面前
            int diffX = role.PicBox.Location.X + role.PicBox.Width
                - PicBox.Location.X;
            int diffY = role.PicBox.Location.Y - PicBox.Location.Y - 10;

            for (int i = 1; i <= 10; i++)
            {
                PicBox.Location = new Point(PicBox.Location.X + diffX / 10,
                   PicBox.Location.Y + diffY / 10);
                BottomLabel.Location = PicBox.Location;
                TopLabel.Location = PicBox.Location;
                Delay(20000);
            }

            role.bloodLoss(this.getAttack() - role.getDefense());
            goBack();
        }
    }
}
